﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DBBase;
namespace Business
{
    public partial class waijianzhaopian : Form
    {
        public string slsh1;
        public string shphm;
        public string shpzl;
        public waijianzhaopian(string slsh,string hphm,string hpzl)
        {
            InitializeComponent();
            shphm = hphm;
            shpzl=hpzl;
           // slsh1 = slsh;

            Query mquery = new Query();
      
            string sql;
            sql = string.Format(@"SELECT * FROM Detects_SJA where DET_LSH ='{0}'", slsh);
            slsh1 = mquery.GetDBString(sql, "DET_LSHZJ");


            getVINdata(slsh1, "WGXM_VIN", pictureBox1);
            getVINdata(slsh1, "WGXM_Q", pic_hgz);
            getVINdata(slsh1, "WGXM_H", pic_xsz);
            getVINdata(slsh1, "WGXM_DP", pic_wqd);
            getVINdata(slsh1, "WGXM_BGD", pic_bgd);
            getVINdata(slsh1, "WGXM_HGZ", pic_hgz2);
            getVINdata(slsh1, "WGXM_XSZ", pic_xsz2);

        }
        public void getVINdata(string lsh,string szd,PictureBox pic)
        {
            Query mquery = new Query();
            string sql;
            sql = string.Format(@"Select * from WJXM Where WGXM_jylsh='{0}' or WGXM_jylsh='{1}'", lsh, slsh1);
            DataTable dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                byte[] content;
                if (dt.Rows[0][szd].ToString().Length > 10)
                {
                    content = (byte[])dt.Rows[0][szd];
                    if (content.Length > 10)
                    {
                        string base64 = Convert.ToBase64String(content);
                        //流数据写到控件上
                        System.IO.MemoryStream ms = new System.IO.MemoryStream(content);
                        //通过流对象建立Bitmap
                        System.Drawing.Bitmap bmp = new Bitmap(ms);
                        //this.pictureIC.Image = bmp;
                        Point ptLoction = new Point(bmp.Size);
                        if (ptLoction.X > pictureBox1.Size.Width || ptLoction.Y > pictureBox1.Size.Height)
                        {
                            //圖像框的停靠方式   
                            //圖像充滿圖像框，並且圖像維持比例   
                            pic.SizeMode = PictureBoxSizeMode.Zoom;
                        }
                        else
                        {
                            //圖像在圖像框置中   
                            pic.SizeMode = PictureBoxSizeMode.CenterImage;
                        }
                        pic.Image = bmp;
                    }
                }
            }
        }


        private void pic_wqd_DoubleClick(object sender, EventArgs e)
        {
            photoform f = new photoform();
            f.pictureBox1.Image = pic_wqd.Image;
            f.ShowDialog();
        }

        private void waijianzhaopian_Load(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

            photoform f = new photoform();
            f.pictureBox1.Image = pictureBox1.Image;
            f.ShowDialog();
        }

        private void pic_hgz_Click(object sender, EventArgs e)
        {
            photoform f = new photoform();
            f.pictureBox1.Image = pic_hgz.Image;
            f.ShowDialog();
        }

        private void pic_bgd_Click(object sender, EventArgs e)
        {
            photoform f = new photoform();
            f.pictureBox1.Image = pic_bgd.Image;
            f.ShowDialog();
        }

        private void pic_xsz2_Click(object sender, EventArgs e)
        {
            photoform f = new photoform();
            f.pictureBox1.Image = pic_xsz2.Image;
            f.ShowDialog();
        }

        private void pic_xsz_Click(object sender, EventArgs e)
        {
            photoform f = new photoform();
            f.pictureBox1.Image = pic_xsz.Image;
            f.ShowDialog();
        }

        private void pic_wqd_Click(object sender, EventArgs e)
        {
            photoform f = new photoform();
            f.pictureBox1.Image = pic_wqd.Image;
            f.ShowDialog();
        }

        private void pic_hgz2_Click(object sender, EventArgs e)
        {
            photoform f = new photoform();
            f.pictureBox1.Image = pic_hgz2.Image;
            f.ShowDialog();
        }
    }
}
